import request from '@/utils/request'
import type { 
  Activity, 
  PaginationParams, 
  PaginationResponse,
  ActivityVoteStatistics 
} from '@/types'

// 活动管理API
export const activityApi = {
  // 获取活动列表
  getList: (params?: PaginationParams & { 
    status?: string; 
    search?: string 
  }) =>
    request.get<PaginationResponse<Activity>>('/admin/activities', { params }),

  // 获取活动详情
  getDetail: (id: number) =>
    request.get<Activity>(`/admin/activities/${id}`),

  // 创建活动
  create: (data: Partial<Activity>) =>
    request.post<Activity>('/admin/activities', data),

  // 更新活动
  update: (id: number, data: Partial<Activity>) =>
    request.put<Activity>(`/admin/activities/${id}`, data),

  // 删除活动
  delete: (id: number) =>
    request.delete(`/admin/activities/${id}`),

  // 添加艺人到活动
  addArtist: (data: { 
    activityId: number; 
    artistId: number; 
    sortOrder?: number 
  }) =>
    request.post(`/admin/activities/${data.activityId}/artists`, data),

  // 从活动移除艺人
  removeArtist: (activityId: number, artistId: number) =>
    request.delete(`/admin/activities/${activityId}/artists/${artistId}`),

  // 更新活动艺人排序
  updateArtistOrder: (activityId: number, data: { 
    artists: Array<{ artistId: number; sortOrder: number }> 
  }) =>
    request.put(`/admin/activities/${activityId}/artists/order`, data),

  // 获取活动投票统计
  getVoteStatistics: (id: number) =>
    request.get<ActivityVoteStatistics>(`/admin/activities/${id}/statistics`)
}
